<?php
/**
 * Jcrop image cropping plugin for jQuery
 * Example cropping script
 * @copyright 2008 Kelly Hallman
 * More info: http://deepliquid.com/content/Jcrop_Implementation_Theory.html
 */

	$lx  = $_POST['left_x'];
	$ly  = $_POST['left_y'];
	$bx  = $_POST['bot_x'];
	$by  = $_POST['bot_y'];
	$img = $_POST['img_src'];
	$targ_w = $bx - $lx;
	$targ_h = $by - $ly;	
	$path = 'E:/wamp/www/qy/upload/product/';
	
	$postion = strripos($img,'/');
	$return_url = substr($img,0,$postion+1);

	$extname = strtolower(substr($img, strrpos($img, '.')));
	$new_img_src =md5(mktime().rand(1000, 9999)).$extname;
	$src = $path.$new_img_src;

	$img_r = imagecreatefromjpeg($img);
	$dst_r = ImageCreateTrueColor( $targ_w, $targ_h );

	imagecopyresampled($dst_r,$img_r,0,0,$lx,$ly,$targ_w,$targ_h,$targ_w,$targ_h);

	header('Content-type: image/jpeg');
	
	imagejpeg($dst_r,$src);
	imagedestroy($dst_r);
	unlink($path.substr($img, $postion+1));
	echo $return_url.$new_img_src;
	exit;
